package com.hyy.lotterysystem.common.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class DelayedRabbitConfig {
    public static final String DELAYED_EXCHANGE_NAME="delayed-exchange";
    public static final String DELAYED_QUEUE_NAME="delayed-queue";
    public static final String DELAYED_BIND_KEY="delayed-queue";//绑定键，就是队列名字
    public static final String DELAYED_ROUTING_KEY="delayed-queue";//绑定键，就是队列名字

    @Bean("delayedExchange")
    public Exchange delayedExchange(){
        return
                ExchangeBuilder.directExchange(DELAYED_EXCHANGE_NAME).durable(true).delayed().build();
    }

    //2. 队列
    @Bean("delayedQueue")
    public Queue delayedQueue() {
        return QueueBuilder.durable(DELAYED_QUEUE_NAME).build();
    }

    //3. 队列和交换机绑定 Binding
    @Bean("delayedBinding")
    public Binding delayedBinding(
            @Qualifier("delayedExchange") Exchange exchange,
            @Qualifier("delayedQueue") Queue queue) {
        return BindingBuilder.bind(queue).to(exchange).with(DELAYED_BIND_KEY).noargs();
    }


}
